package weaver.splittable;
import weaver.general.BaseBean;
import weaver.splittable.biz.STBizDataCleaner;

import java.util.Map;

public class STDocUtil {

    public static boolean isInitialized(){
        return STInstaller.isInstalled();
    }

    // 获取数据库类型
    public static String getDBType() {
        String URL = new BaseBean().getPropValue("weaver", "ecology.url");
        if (URL.indexOf(":oracle") >= 0) {
            return "oracle";
        } else if (URL.indexOf(":sqlserver") >= 0) {
            return "sqlserver";
        } else if (URL.indexOf(":mysql") >= 0) {
            return "mysql";
        } else if (URL.indexOf(":oceanbase") >= 0) {
            return "oceanbase";
        } else if (URL.indexOf(":oscar") >= 0) {
            return "oscar";
        } else if (URL.contains(":kingbase")) {
            return "kingbase";
        } else if (URL.contains(":zenith")) {
            return "zenith";
        } else if (URL.indexOf(":gbase") >= 0) {
            return "gbase";
        } else if (URL.indexOf(":dm") >= 0) {
            return "dm";
        } else if (URL.indexOf(":db2") >= 0) {
            return "db2";
        } else if (URL.indexOf("postgresql") > 0) {
            return "postgresql";
        } else if (URL.indexOf("highgo") > 0) {
            return "highgo";
        } else if (URL.indexOf("gaussdb") > 0) {
            return "gaussdb";
        }
        return "";
    }

    // 分表年限
    public static String getSplitTime() {
        return STConfig.SPLIT_TIME;
    }

    // 同步间隔
    public static String getSyncTime() {
        return STConfig.SYNC_TIME;
    }

    // 中间表数据保留天数
    public static String getKeepSplitTableTime() {
        return STConfig.KEEP_SPLIT_TABLE_TIME;
    }

    // 中间表数据保留天数
    public static String getFullDataApiSet() {
        return STConfig.FULL_DATA_API_SET.toString();
    }

    // 获取全量表创建SQL
    public static String getCreateFullDataSQL(String tableName) {
        return STContext.CREATE_TABLE().createFullDataTable(tableName);
    }

    // 获取需要分表的表信息
    public static Map<String, String> getSplitTables() {
        return STContext.SPLIT_TABLES();
    }

    // 获取活跃表清理SQL
    public static String getClearDataSQL(String bizName, String tableName) {
        STContext.BIZ_INTERCEPTORS(bizName).init();
        STBizDataCleaner bizDataCleaner = STContext.BIZ_DATA_CLEANER(bizName);
        return bizDataCleaner.getClearSql(tableName);
    }

}
